﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.crew.ui {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Mechanics.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import flash.text.*;
    import org.aswing.border.*;
    import Display.aswingui.*;
    import Mechanics.GameEventMechanics.*;
    import com.zynga.skelly.util.*;

    public class RollCallIntroDialogView extends GenericDialogView {

        private static const MAX_DISPLAY_CREW:int = 4;

        protected var m_mechData:RollCallDataMechanic;
        protected var m_rewardData:TieredDooberMechanic;
        private var m_nextRewardIndex:int = 0;
        private var m_checkinsLeft:int = 0;

        public function RollCallIntroDialogView(_arg1:Dictionary, _arg2:String="", _arg3:String="", _arg4:int=0, _arg5:Function=null, _arg6:String="", _arg7:int=0, _arg8:String="", _arg9:Function=null, _arg10:String=""){
            this.m_mechData = (MechanicManager.getInstance().getMechanicInstance(_arg1["spawner"], "rollCall", MechanicManager.ALL) as RollCallDataMechanic);
            this.m_rewardData = (MechanicManager.getInstance().getMechanicInstance(_arg1["spawner"], "rollCallTieredDooberValue", MechanicManager.ALL) as TieredDooberMechanic);
            super(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10);
        }
        public function get nextRewardIndex():int{
            return (this.m_nextRewardIndex);
        }
        public function set nextRewardIndex(_arg1:int):void{
            this.m_nextRewardIndex = _arg1;
        }
        public function get checkinsLeft():int{
            return (this.m_checkinsLeft);
        }
        public function set checkinsLeft(_arg1:int):void{
            this.m_checkinsLeft = _arg1;
        }
        override protected function createInteriorHolder():JPanel{
            var _local1:JPanel;
            var _local3:JPanel;
            _local1 = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.TOP));
            var _local2:JPanel = createHeaderPanel();
            ASwingHelper.prepare(_local2);
            textArea = this.createTextArea();
            ASwingHelper.prepare(textArea);
            _local1.setBorder(new EmptyBorder(null, new Insets(0, 0, 0, 0)));
            _local1.append(ASwingHelper.verticalStrut(2));
            if (m_type != TYPE_NOBUTTONS){
                _local1.append(_local2);
            };
            _local1.append(ASwingHelper.verticalStrut(2));
            _local1.append(textArea);
            _local1.append(ASwingHelper.verticalStrut(-5));
            if (((!((m_type == TYPE_MODAL))) && (!((m_type == TYPE_NOBUTTONS))))){
                _local3 = createButtonPanel();
                _local1.append(_local3);
            };
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        override protected function createTextArea():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, 5);
            _local1.setPreferredWidth(m_bgAsset.width);
            ASwingHelper.setEasyBorder(_local1, 0, 8);
            var _local2:JPanel = this.makeSamPanel();
            var _local3:JPanel = this.makeRewardsPane();
            _local1.appendAll(_local2, _local3);
            return (_local1);
        }
        protected function makeBorder():AssetPane{
            var _local1:Sprite = new Sprite();
            _local1.graphics.beginFill(EmbeddedArt.lightBlueTextColor);
            _local1.graphics.drawRoundRect(0, 0, 3, 78, 2, 2);
            _local1.graphics.endFill();
            var _local2:AssetPane = new AssetPane(_local1);
            return (_local2);
        }
        protected function makeRewardsPane():JPanel{
            var _local1:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER, 10);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            var _local3:JLabel = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "RollCall_24hours"), EmbeddedArt.TITLE_FONT, 20, EmbeddedArt.lightOrangeTextColor, JLabel.RIGHT);
            var _local4:JLabel = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "RollCall_toCheckIn"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, EmbeddedArt.blueTextColor, JLabel.RIGHT);
            _local2.appendAll(_local3, _local4);
            var _local5:AssetPane = new AssetPane((new (m_assetDict["payroll_icon_clock"])() as DisplayObject));
            _local1.appendAll(_local2, ASwingHelper.topAlignElement(_local5), this.makeBorder(), this.generateRewardPane());
            return (_local1);
        }
        protected function generateRewardPane():JPanel{
            var rewardComplete:* = false;
            var tierObj:* = null;
            var checkinsNeeded:* = 0;
            var tierRewardObject:* = null;
            var key:* = null;
            var rewardAsset:* = null;
            var reward:* = null;
            var rewardPane:* = null;
            var tierName:* = null;
            var itemName:* = null;
            var tierAmount:* = NaN;
            var item:* = null;
            var itemLoader:* = null;
            var jp:* = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT, 10);
            var numTiers:* = this.m_rewardData.getNumTiers();
            var i:* = 1;
            while (i < numTiers) {
                tierObj = this.m_rewardData.getTierInfo(i);
                checkinsNeeded = tierObj.num;
                tierRewardObject = this.m_rewardData.getTierRewardInfo(i);
                for (key in tierRewardObject) {
                    tierName = key.toString();
                    itemName = "";
                    tierAmount = 0;
                    if ((tierRewardObject[key] is Number)){
                        tierAmount = tierRewardObject[key];
                    } else {
                        itemName = tierRewardObject[key].name;
                        tierAmount = tierRewardObject[key].count;
                    };
                };
                rewardAsset = new Sprite();
                switch (tierName){
                    case "coin":
                        rewardAsset = (new (m_assetDict["payroll_reward_coin"])() as DisplayObject);
                        break;
                    case "xp":
                        rewardAsset = (new (m_assetDict["payroll_reward_xp"])() as DisplayObject);
                        break;
                    case "energy":
                        rewardAsset = (new (m_assetDict["payroll_reward_energy"])() as DisplayObject);
                        break;
                    case "item":
                        item = Global.gameSettings.getItemByName(itemName);
                        if (item){
                            itemLoader = LoadingManager.load(item.icon, Curry.curry(function (_arg1:JPanel, _arg2:Event):void{
                                if ((rewardAsset is DisplayObjectContainer)){
                                    (rewardAsset as DisplayObjectContainer).addChild(itemLoader.content);
                                    itemLoader.content.x = (itemLoader.content.x - (itemLoader.content.width / 2));
                                    itemLoader.content.y = (itemLoader.content.y - (itemLoader.content.height / 2));
                                };
                                ASwingHelper.prepare(_arg1);
                                _arg1.dispatchEvent(new UIEvent(UIEvent.REFRESH_DIALOG, "itemIconLoaded", true));
                            }, this));
                        };
                        break;
                };
                reward = new CrewRewardIntroSprite(m_assetDict, rewardAsset, tierAmount);
                rewardPane = new AssetPane(reward);
                if (!rewardComplete){
                    ASwingHelper.setEasyBorder(rewardPane, 15);
                };
                jp.append(rewardPane);
                if (i != 3){
                    jp.append(new AssetPane((new (m_assetDict["payroll_rewardArrow"])() as DisplayObject)));
                };
                i = (i + 1);
            };
            return (jp);
        }
        protected function makeSamPanel():JPanel{
            var _local10:JPanel;
            var _local11:JPanel;
            var _local12:JLabel;
            var _local13:JLabel;
            var _local1:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT, 10);
            var _local2:AssetPane = new AssetPane((new (m_assetDict["payroll_sam_pigeon"])() as DisplayObject));
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, 20);
            var _local4:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT, 20);
            var _local5:Array = this.m_mechData.getCrewList();
            var _local6 = "";
            var _local7:int;
            while (_local7 < Math.min(_local5.length, MAX_DISPLAY_CREW)) {
                _local10 = ASwingHelper.makeFriendImageFromZid(_local5[_local7]);
                _local4.append(_local10);
                if (_local5[_local7].substr(0, 1) == "-"){
                    _local6 = (_local6 + (ZLoc.t("Main", "FakeFriendName") + ", "));
                } else {
                    if (Global.player.isFriendIDInList(_local5[_local7])){
                        _local6 = (_local6 + (Global.player.findFriendById(_local5[_local7]).firstName + ", "));
                    };
                };
                _local7++;
            };
            if (_local5.length > MAX_DISPLAY_CREW){
                _local11 = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
                _local12 = ASwingHelper.makeLabel(("+" + String((_local5.length - MAX_DISPLAY_CREW))), EmbeddedArt.TITLE_FONT, 18, EmbeddedArt.whiteTextColor, JLabel.CENTER);
                _local13 = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "RollCall_more"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 10, EmbeddedArt.whiteTextColor, JLabel.CENTER);
                _local11.appendAll(_local12, _local13);
                _local4.append(_local11);
            };
            var _local8:String = ZLoc.t("Dialogs", "RollCall_getfriends", {friendNames:_local6});
            var _local9:AssetPane = ASwingHelper.makeMultilineText(_local8, 435, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.LEFT, 16, EmbeddedArt.blueTextColor);
            _local3.appendAll(_local4, _local9);
            _local1.appendAll(_local2, ASwingHelper.topAlignElement(_local3));
            return (_local1);
        }
        override protected function makeBackground():void{
            if (m_bgAsset){
                ASwingHelper.setSizedBackground(this, m_bgAsset, new Insets(0, 0, 10, 0));
            };
        }

    }
}//package Modules.crew.ui 
